#pragma once

#include "IEvent.h"
#include "Pointer.h"
#include <map>

class EventHandler
{
public:
	typedef std::multimap<const HashedString, Pointer<EventHandler>> Map_t;
	typedef std::pair<const HashedString, Pointer<EventHandler>> Pair_t;
	virtual bool operator ()(IEvent&)=0;
	virtual void* getPointer() = 0;
};

template<class T>
class CEventHandler : public EventHandler
{
protected:
	Pointer<T> obj;
	typedef bool (T::*funcType)(IEvent&);
	funcType func;
public:
//	CEventHandler(T *o, funcType f) 
//	{ 
//		obj=o; 
//		func=f; 
//	}
	CEventHandler(Pointer<T> o, funcType f) 
	{ 
		obj=o; 
		func=f; 
	}
	Pointer<T>& getObject()
	{
		return obj;
	}
	bool operator ()(IEvent& event) 
	{ 
		return (obj->*func)(event); 
	}
	void* getPointer()
	{
		return obj.getPointer();
	}
};
